/********************************************************************************
*																				*
*  Las Venturas Playground - Core/IRC.nut										*
*																				*
*  Everything related to the IRC ECHO is located here.							*
*  Based on IV:MP IRC Module v1.0												*
*																				*
********************************************************************************/

/*

IV:MP IRC Module v1.0

Basic example script (Beta 1)

*/

local iBot;
local strEchoChannel = "#LVP.IV";

//
// Define the server, port, nickname, realname, ident, ssl.
//
function onScriptInit()
{
	ircRegisterMe();
	iBot = ircConnect("irc.gtanet.com", 6667, "LVP_IV", "LVP_IV", "LVP_IV", false, "");
	return true;
}
addEvent("scriptInit", onScriptInit);

//
// Join the IRC channel
//
function ircOnConnect(iBotid)
{
	print("connect");
	ircJoinChannel(iBotid, strEchoChannel);
	return true;
}

//
// I have no clue.
//
function ircOnReceiveRaw(botid, data)
{
	return true;
}

//
// Show a new connection at IRC.
//
function onPlayerConnect(playerid)
{
	ircSay(iBot, strEchoChannel, "02[" + playerid + "] 03*** " + getPlayerName(playerid) + " has joined the server.");
	return true;
}
addEvent("playerConnect", onPlayerConnect);

//
// Show the disconnect reason at IRC.
//
function onPlayerDisconnect( playerid, reason )
{
	// We set the disconnect reason.
	local sDisconnectReason = "Quit";
	
	if( reason == 1 )
	{
		sDisconnectReason = "Timeout/Crash";
	}
	
	// Inform the rest of the players
	ircSay(iBot, strEchoChannel, "02[" + playerid + "] 03*** " + getPlayerName(playerid) + " has left the server (" + sDisconnectReason + ").");
	return 1;
}
addEvent("playerDisconnect", onPlayerDisconnect);

//
// Show the in-game chat at IRC.
//
function onPlayerText(playerid, text)
{
	ircSay(iBot, strEchoChannel, "02["+playerid+"] 07" + getPlayerName(playerid) + ": " + text);
	return true;
}
addEvent("playerText", onPlayerText);

//
// Show a death message at IRC.
//
function onPlayerDeath(playerid, killerid)
{
	//	sendMessageToAll(getPlayerName(killerid) + " Has killed " + getPlayerName(playerid) + " with a " + WeaponNames[getPlayerWeapon(killerid)] + " (Distance: " + getDistanceBetweenPoints3D(pos1[0], pos1[1], pos1[2], pos2[0], pos2[1], pos2[2]) + " ft)", COLOR_GREEN);
	ircSay(iBot, strEchoChannel, "04*** " + getPlayerName(playerid) + " (ID:"+playerid+") died.");
    return 1;
}
addEvent("playerDeath", onPlayerDeath);

//
// Show IRC chat in-game.
//
//function ircOnUserSay(botid, receiver, user, host, message)
//{
//	sendMessageToAll("[irc] <" + user + "> " + message, 0xFFFFFFAA);	
//	return true;
//}
